//
//  AddressTableCell.swift
//  koolcar
//
//  Created by xiantian on 2023/10/25.
//

import UIKit

class MaintenceAddressTableCell: UITableViewCell {
    var imgView: UIImageView!
    var addressLab: UILabel!
    var bkgView: UIView!
    var selectImgBtn: UIButton!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = Theme.viewBkgGrayColor
        
        bkgView = UIView()
        bkgView.layer.cornerRadius = 4
        bkgView.layer.masksToBounds = true
        bkgView.backgroundColor = .white
        contentView.addSubview(bkgView)
        
        imgView = UIImageView()
        imgView.layer.cornerRadius = 4
        imgView.layer.masksToBounds = true
        imgView.backgroundColor = Theme.eColor
        bkgView.addSubview(imgView)
        
        addressLab = UILabel()
        addressLab.textColor = Theme.titleLabColor
        addressLab.backgroundColor = UIColor.clear
        addressLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        addressLab.numberOfLines = 0
        addressLab.lineBreakMode = .byTruncatingTail
        addressLab.textAlignment = .left
        //addressLab.text = "观塘鸿图道45号宏光工业大厦地下B铺"
        bkgView.addSubview(addressLab)
        
        selectImgBtn = UIButton()
        selectImgBtn.isHidden = true
        selectImgBtn.isUserInteractionEnabled = false
        selectImgBtn.setup_image(image: UIImage.init(named: "icon_brand_select"))
        bkgView.addSubview(selectImgBtn)
        
        self.addSnpLayout()
    }
    
    private func addSnpLayout(){
        bkgView.snp.makeConstraints { make in
            make.top.equalTo(20)
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.bottom.equalTo(0).priority(.high)
        }
        
        imgView.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.top.equalTo(0)
            make.width.equalTo(100)
            make.height.equalTo(100).priority(.high)
            make.bottom.equalTo(0)
        }
        
        addressLab.snp.makeConstraints { make in
            make.left.equalTo(imgView.snp.right).offset(10)
            make.top.equalTo(15)
            make.height.greaterThanOrEqualTo(20)
        }
        
        selectImgBtn.snp.makeConstraints { make in
            make.right.equalTo(-2)
            make.centerY.equalTo(50)
            make.width.equalTo(34)
            make.height.equalTo(34)
            make.left.equalTo(addressLab.snp.right).offset(10)
        }
    }
    
    func setMaintenceAddressTableCell(data: StoreUsedcarListModel)  {
        self.addressLab.text = data.address ?? ""
        if let url = URL.init(string: data.backgroundImages ?? "") {
            self.imgView.sd_setImage(with: url, placeholderImage: UIImage.init(named: "icon_default_place_v"))
        }else{
            self.imgView.image = UIImage.init(named: "icon_default_place_v")
        }
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
